package my.OrderMessage;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class PhoneRegistration extends Activity {
	public static Context mContext;
	
    public void onCreate(Bundle savedInstanceState) {
    	  super.onCreate(savedInstanceState);
    	  setContentView(R.layout.intro);
    	  
    	  mContext = this;
    	  
    	  Button savaButton = (Button) findViewById(R.id.button1);
    	  Button cancleButton = (Button) findViewById(R.id.button2);

    	  // 저장 버튼 클릭시
    	  savaButton.setOnClickListener(new OnClickListener() {
  			@Override
  			public void onClick(View arg0) {
  				// TODO Auto-generated method stub
  	    		//C2DM 핸폰별 등록ID 발급
  				EditText nameEditText = (EditText)findViewById(R.id.editText1);
  				
  				if (nameEditText.getText().toString().equals(""))	{
  					Toast.makeText(getApplicationContext(), "이름을 넣어주세요", Toast.LENGTH_SHORT).show();
  				} else {
  					phoneRegister();
  				}
  			}
  		});
    	  
    	  // 취소시 종료
    	  cancleButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				finish();				
			}
		});
    } // onCreate End
    
    public void phoneRegister() {
    	Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");
  		registrationIntent.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent(), 0)); // 어플리케이션ID
  		registrationIntent.putExtra("sender", "ayukawa7777@gmail.com"); //개발자ID
  		startService(registrationIntent); // 서비스 시작(등록ID발급받기), 구글서버에 값이 전달된 후 브로드캐스트 발생 
  		                                  // C2DMReceiver.java의 onReceive이 호출됨  액션값은 com.google.android.c2dm.intent.REGISTRATION
    } // phoneRegister End
    
    public String returnName() {
    	EditText nameEditText = (EditText)findViewById(R.id.editText1);
    	return nameEditText.getText().toString();
    } //가
    
}
